<?php
$path =  str_replace('/wp-content/plugins/stSocialMediaToolbox/Toolboxes/stFacebookToolbox/cronjob','',dirname(__FILE__));
require($path.'/wp-config.php');
require_once $path.'/wp-content/plugins/stSocialMediaToolbox/Toolboxes/stFacebookToolbox/libs/2.1/classes/facebook/facebook.php';
        function get_facebook_wall($pageid){
                define('APP_API_KEY', '295014677178053');
		define('APP_SECRET_KEY', '39c394b87ad3fd9de7a4e5d5c31e0569');
		define('APP_ID', '295014677178053');
              	$facebook = new Facebook(APP_API_KEY, APP_SECRET_KEY, true);
		$pageId = $pageid;
		$infos = $facebook->api_client->stream_get(0, $pageId, null, null, 1000);
		$posts = $infos['posts'];
		$profiles = $infos['profiles'];
		$users = array();
		if(is_array($profiles)){

			foreach($profiles as $pr) {
				$users[$pr['id']] = $pr;
			}
		}
		$generalInformation1 = json_decode(file_get_contents("http://graph.facebook.com/{$pageId}"));
		$generalInformation = array();
		$generalInformation['number_post'] = 0;
		$generalInformation['number_comment'] = 0;
		$generalInformation['number_like'] = 0;
		$generalInformation['number_share'] = 0;
		$generalInformation['number_user'] = count($profiles);

		$hrefs = array();

		foreach($generalInformation1 as $k => $v) {
			$generalInformation[$k] = $v;
		}
		//fan_count
		if(is_array($posts)){
		foreach($posts as $k => $post) {
			$generalInformation['number_post']++;
			$generalInformation['number_comment']+= $post['comments']['count'];
			$generalInformation['number_like']+= @$post['likes']['count'];
			if(isset($post['attachment']['href'])) {
				$hrefs[] = urlencode($post['attachment']['href']);
			}
		}
		}
		if(count($hrefs) > 0) {
			$hrefString = implode(",",$hrefs);
			$xml = simplexml_load_file('http://api.facebook.com/restserver.php?method=links.getStats&urls='.$hrefString, NULL, LIBXML_NOBLANKS);
			foreach($xml->link_stat as $item) {
				$generalInformation['number_share'] += $item->share_count;
			}
		}

		return json_encode($generalInformation);

    }
    $result = get_facebook_wall('108085495883406');
    echo '<pre>';
    var_dump($result);
?>